<?php

/*
 * Copyright 2018 zhuo bing.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace backend\models;
use Yii;
use yii\caching\TagDependency;
use yii\db\ActiveRecord;
/**
 * Description of Region
 *
 * @author zhuo bing
 */
class Region extends ActiveRecord {
    const PROVINCE = 1;
    const CITY = 2;
    const COUNTY = 3;
    static protected $types = [self::PROVINCE => 'province',self::CITY => 'city', self::COUNTY => 'county'];
    
    static public function getCurrSubNode($pid = 1) {
        $cache = Yii::$app->cache;
        $list = $cache->getOrSet("regionSub:$pid", function()use($pid){
           return $list = self::find()->where(['parent' => $pid])->asArray()->all();
        },0,new TagDependency(['tags' => 'region']));
        
        return $list;
    }
    static public function getParentsNode($pid){
        
    }
}
